<template>
  <div class="water-wrapper">
    <!-- //水质标准 -->
    <el-row>
      <el-col :span="24" class="common-top-viscous-style">
        <el-row>
          <el-col :span="12">
            <el-input
              v-model="filter.name"
              class="search"
              size="small"
              placeholder="请输入检索内容"
              suffix-icon="el-icon-search"
              clearable
              @change="getSysStandardList"
              @clear="getSysStandardList"
            />
            <!-- <el-input
              v-model="filter.sname"
              placeholder="请输入内容"
              type="text"
              onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
            /> -->
          </el-col>
          <el-col :span="12" align="right">
            <el-button type="primary" size="small" @click="addWaterFn">添加水质标准</el-button>
          </el-col>
        </el-row>
      </el-col>
      <el-col :span="24">
        <el-table :data="waterStandardList" size="small">
          <el-table-column
            v-for="item in waterColumns"
            :key="item.key"
            :prop="item.key"
            :label="item.title"
          />
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="editWaterFn(scope.row)">编辑</el-button>
              <el-button type="text" size="small" @click="delWorksFn(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <Save ref="waterMap" :save-obj="saveObj" @getSysStandardFn="getSysStandardList" />
  </div>
</template>

<script>
import {
  getSysStandardList,
  delSysStandard
} from '@/api/infoConfig/waterStandard'
import Save from './save/save'
export default {
  components: {
    Save
  },
  data() {
    return {
      filter: {
        name: ''
      },
      waterColumns: [
        {
          key: 'stdName',
          title: '标准名称',
          width: 180
        },
        {
          key: 'phUpper',
          title: 'ph上限值',
          width: 180
        },
        {
          key: 'phLower',
          title: 'ph下限值',
          width: 180
        },
        {
          key: 'codUpper',
          title: 'cod上限值',
          width: 180
        },
        {
          key: 'codLower',
          title: 'cod下限值',
          width: 180
        },
        {
          key: 'nh3Upper',
          title: '氨氮上限值',
          width: 180
        },
        {
          key: 'nh3Lower',
          title: '氨氮下限值',
          width: 180
        },
        {
          key: 'tnUpper',
          title: 'tn上限值',
          width: 180
        },
        {
          key: 'tnLower',
          title: 'tn下限值',
          width: 180
        },
        {
          key: 'tpUpper',
          title: 'tp上限值',
          width: 180
        },
        {
          key: 'tpLower',
          title: 'tp下限值',
          width: 180
        }
      ],
      waterStandardList: [],
      saveObj: {
        show: false,
        title: '',
        data: {
          stdUid: '',
          stdName: '',
          phUpper: '',
          phLower: '',
          codUpper: '',
          codLower: '',
          nh3Upper: '',
          nh3Lower: '',
          tnUpper: '',
          tnLower: '',
          tpUpper: '',
          tpLower: ''
        }
      }
    }
  },
  mounted() {
    this.getSysStandardList()
  },
  methods: {
    getSysStandardList() {
      // console.log(this.filter.name)
      getSysStandardList({ name: this.filter.name }).then(res => {
        console.log(res.data, '123')
        this.waterStandardList = res.data
      })
    },
    // 添加水质标准
    addWaterFn() {
      this.saveObj.show = true
      this.saveObj.title = '添加水质标准'
      this.saveObj.data = {
        stdUid: '',
        stdName: '',
        phUpper: '',
        phLower: '',
        codUpper: '',
        codLower: '',
        nh3Upper: '',
        nh3Lower: '',
        tnUpper: '',
        tnLower: '',
        tpUpper: '',
        tpLower: ''
      }
      this.$refs.waterMap.getFormFn()
      this.$refs.waterMap.checkIsEdit(false)
    },
    // 编辑水质
    editWaterFn(row) {
      this.saveObj.show = true
      this.saveObj.title = '编辑水质标准'
      this.saveObj.data = JSON.parse(JSON.stringify(row))
      this.$refs.waterMap.getFormFn()
      this.$refs.waterMap.checkIsEdit(true)
    },
    // 删除水质
    delWorksFn(row) {
      // console.log(row)
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          delSysStandard({ uid: row.stdUid }).then(res => {
            // console.log(res)
            this.getSysStandardList()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>
<style lang="sass">
  @import "./waterStandard"
</style>

